home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / generic / generic.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.8 KB  |  208 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1999 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #include "resource.h"
  13.  
  14. #define WINDOW_WIDTH 480
  15. #define WINDOW_HEIGHT 214
  16. int ClientWidth;
  17. int ClientHeight;
  18. #define SQUARE_SIZE (WINDOW_WIDTH / 6)
  19. #define LOWER_LEFT 20
  20.  
  21. // Define a window class derived from CFrameWnd
  22. class CMainWindow : public CFrameWnd
  23. {
  24. private:
  25.     CPoint m_LowerLeft[LOWER_LEFT];
  26.     WORD m_nLowerLefts;
  27.     BOOL m_bMouseDown;
  28.     int m_nCaptionSize;
  29.  
  30. public:
  31.     CMainWindow();
  32.  
  33.     //{{AFX_MSG( CMainWindow )
  34.     afx_msg void OnFileExit();
  35.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  36.     afx_msg void OnPaint();
  37.     //}}AFX_MSG
  38.  
  39.     DECLARE_MESSAGE_MAP()
  40. };
  41.  
  42. class CAboutDlg: public CDialog
  43. {
  44. public:
  45.     CAboutDlg::CAboutDlg() 
  46.     {CDialog(IDD_ABOUT);}
  47. };
  48.  
  49. // Define an application class derived from CWinApp
  50. class CGenericApp : public CWinApp
  51. {
  52. public:
  53.     virtual BOOL InitInstance();
  54.  
  55.     DECLARE_MESSAGE_MAP()
  56. };                  
  57.  
  58. //////////////////////////////////////////////////////////////////////////
  59. //  Implementation
  60. //////////////////////////////////////////////////////////////////////////
  61.  
  62. // Create the application's main window and perform initialization chores
  63. BOOL CGenericApp::InitInstance()
  64. {
  65.     m_pMainWnd = new CMainWindow();
  66.     m_pMainWnd->ShowWindow( m_nCmdShow );
  67.     m_pMainWnd->UpdateWindow();
  68.  
  69.     CRect rect;
  70.     m_pMainWnd->GetClientRect(&rect);
  71.     ClientWidth = rect.right;
  72.     ClientHeight = rect.bottom;
  73.     m_pMainWnd->InvalidateRect(rect);
  74.  
  75.     return (TRUE);
  76. }
  77.  
  78. // CEtchaApp's contructor initializes and runs the app
  79. CGenericApp goGenApp;
  80.  
  81. CMainWindow::CMainWindow()
  82. : m_bMouseDown(FALSE),
  83. m_nLowerLefts(0),
  84. m_nCaptionSize(GetSystemMetrics(SM_CYCAPTION))
  85. {
  86.     LoadFrame(IDR_MAINFRAME);
  87.  
  88.     // For MFCCE 2.0 and earlier, a command bar was created during
  89.     // the CFrameWnd creation. For MFCCE 2.01 and later, a command bar 
  90.     // is automatically created for you during the call to AddAdornments().
  91.     AddAdornments(0);
  92. }
  93.  
  94. // CMainWindow message map:
  95. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  96.     //{{AFX_MSG_MAP( CMainWindow )
  97.     ON_WM_LBUTTONDOWN()
  98.     ON_WM_PAINT()
  99.     //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101.  
  102. // CGenericApp message map:
  103. BEGIN_MESSAGE_MAP( CGenericApp, CWinApp )
  104.     //{{AFX_MSG_MAP( CGenericApp)
  105.     //}}AFX_MSG_MAP
  106.     ON_COMMAND(ID_FILE_EXIT, CWinApp::OnAppExit)
  107. END_MESSAGE_MAP()
  108.  
  109. void CMainWindow::OnLButtonDown(UINT nFlags, CPoint point) 
  110. {
  111.     CPoint pos = point;
  112.  
  113.     if (m_bMouseDown = TRUE)
  114.     {
  115.         m_bMouseDown = FALSE;
  116.         ReleaseCapture();
  117.     }
  118.  
  119.     // Confirm that pos is not on command bar
  120.     if (pos.y > m_poCommandBar->GetHeight())
  121.     {
  122.         if (pos.x < (ClientWidth / 2))
  123.         {
  124.             if (pos.y < (ClientHeight / 2))
  125.             {
  126.                 // Upper left quadrant
  127.                 // Exit the application
  128.                 SendMessage(WM_CLOSE);
  129.                 return;
  130.             }
  131.             else
  132.             {
  133.                 // Lower left quadrant
  134.                 // Change Z Order of window to 'bottom'
  135.                 SetWindowPos(&wndBottom, 0, 0, 0, 0,
  136.                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  137.             }
  138.         }
  139.         else
  140.         {
  141.             if (pos.y < (ClientHeight / 2))
  142.             {
  143.                 // Upper right quadrant
  144.                 if (!m_bMouseDown)
  145.                 {
  146.                     SetCapture();
  147.                     m_bMouseDown = TRUE;
  148.                 }
  149.                 else
  150.                 {
  151.                     m_bMouseDown = FALSE;
  152.                     ReleaseCapture();
  153.                 }
  154.                 return;
  155.             }
  156.             else
  157.             {
  158.                 // Lower right quadrant
  159.                 if (m_nLowerLefts < LOWER_LEFT)
  160.                 {
  161.                     if (this != GetFocus())
  162.                         SetFocus();
  163.  
  164.                     m_LowerLeft[m_nLowerLefts].x = pos.x;
  165.                     m_LowerLeft[m_nLowerLefts].y = pos.y;
  166.                     m_nLowerLefts++;
  167.                     // Repaint window
  168.                     CRect rect;
  169.                     GetClientRect(&rect);
  170.                     InvalidateRect(rect);
  171.                 }
  172.             }
  173.         }
  174.     }
  175.  
  176.     CFrameWnd::OnLButtonDown(nFlags, point);
  177. }
  178.  
  179. void CMainWindow::OnPaint() 
  180. {
  181.     CPaintDC dc(this); // device context for painting
  182.     
  183.     CPoint line[5];
  184.     
  185.     // Paints a vertical line that bisects the window
  186.     line[0] = CPoint(ClientWidth / 2, 0);
  187.     line[1] = CPoint(ClientWidth / 2, ClientHeight);
  188.     dc.Polyline(line, 2);
  189.  
  190.     // Paints a horizontal line that bisects the window
  191.     line[0] = CPoint(0, (ClientHeight + m_nCaptionSize) / 2);
  192.     line[1] = CPoint(ClientWidth - 1, (ClientHeight + m_nCaptionSize) / 2);
  193.     dc.Polyline(line, 2);
  194.  
  195.     // Paint any small squares at the point captured
  196.     // (See OnLButtonDown for lower right quadrant)
  197.     for (WORD i = 0; i < m_nLowerLefts; i++)
  198.     {
  199.         line[3].x = line[4].x = line[0].x = m_LowerLeft[i].x;
  200.         line[1].y = line[4].y = line[0].y = m_LowerLeft[i].y;
  201.         
  202.         line[2].x = line[1].x = (line[0].x - SQUARE_SIZE);
  203.         line[2].y = line[3].y = (line[0].y - SQUARE_SIZE);
  204.  
  205.         dc.Polyline(line, 5);
  206.     }
  207. }
  208.